<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts/core'
import { TooltipComponent, LegendComponent } from 'echarts/components'
import { PieChart } from 'echarts/charts'
import { CanvasRenderer } from 'echarts/renderers'

echarts.use([TooltipComponent, LegendComponent, PieChart, CanvasRenderer])
import resizeEcharts from '@/utils/resizeEcharts'
require('echarts/theme/macarons') // echarts theme

export default {
  mixins: [resizeEcharts],
  props: {
    className: {
      type: String,
      default: 'myChart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '330px'
    }
  },
  data() {
    return {
      myChart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.myChart) {
      return
    }
    this.myChart.dispose()
    this.myChart = null
  },
  methods: {
    initChart() {
      this.myChart = echarts.init(this.$el, 'macarons')

      this.myChart.setOption({
        
       title: {
        text: '涉及留证商品',
        x:'center'
    },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['食品', '服饰', '电子设备', '医药', '美妆']
        },
        series: [
          {
            name: '占比',
            type: 'pie',
            roseType: 'radius',
            radius: [15, 95],
            center: ['50%', '48%'],
            data: [
              { value: 320, name: '食品' },
              { value: 240, name: '服饰' },
              { value: 149, name: '电子设备' },
              { value: 100, name: '医药' },
              { value: 59, name: '美妆' }
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>
